package com.hh.hot100;

/**
 * @Author hanghao
 * @Date 2023/6/27 16:07
 * @Version 1.0
 * middle
 * 最大子数求和
 */

public class No53 {
    public int maxSubArray(int[] nums) {
        int res = nums[0];
        int[] dp = new int[nums.length];
        dp[0] = nums[0];
        for (int i = 1; i < nums.length; i++) {
            dp[i] = Math.max(dp[i - 1] + nums[i], nums[i]);
            res = dp[i] > res ? dp[i] : res;
        }
        return res;
    }
}
